<style>
	#sp {
	width:33.1%;
	float:left;
	height:300px;
	background:#fff;
	border-top: 1px solid #E4E4E4;
	border-left: 1px solid #E4E4E4;
	text-align:center;

	}
	#khung {
		float:left;
		width:650px;
		border: 4px solid #E4E4E4;
		text-align:center;
		margin-left:6px;
	}
	#trang {
		width:650px;
		text-align:center;
	}
</style>

<?php
	function tinh_so_trang($so_gioi_han)	// hàm tính số trang.
	{
		$sql="select count(*) from dm_sanpham";
		$sql1=mysql_query($sql);
		$data=mysql_fetch_row($sql1);
		$st=ceil($data[0]/$so_gioi_han);
		return $st;
	}
	$ssp_td=3;	// số sản phẩm tối đa trên dòng.
	$sd=4;	//số dòng tối đa.
	$so_gioi_han=$ssp_td*$sd;	//số sản phẩm tối đa trên 1 trang.
	if($_GET['trang']=="")
	{
		$vtbd=0;	//vị trí bắt đầu = 0.
	}
	else
	{
		$vtbd=($_GET['trang']-1)*$so_gioi_han;
	}
	$st=tinh_so_trang($so_gioi_han);	// số trang.
	//echo $st."<hr>";
	//echo "<table border='1' align='center'>";
	//echo "<tr>";
	//echo "<td>";
	echo "<div id='khung'>";
		$sql="select * from dm_sanpham order by idsp desc limit $vtbd,$so_gioi_han";
		$data=mysql_query($sql);
		while ($row=mysql_fetch_array($data))
		{
			$link="?thamso=tt&idsp=$row[idsp]";
			echo "<div id='sp'>";
				echo "<div style='height:50px' id='khongmau'>";
					echo "<font size='3' color='#FF0000'><a href='$link'>".$row['tensp']."</a></font><br>";
				echo "</div>";
				echo "<a href='$link'><img src='image/ha_sp/".$row['hinh']."' border='0' width='150px' height='150px'></a><br>";
				$dinh_dang_gia=number_format($row['gia'],0,",",".");
				echo "<font size='3' color='#FF0000'><b>".$dinh_dang_gia." VND</b></font><br>";
				echo "<form action='' method=''>";
					echo "<font size='3' color='#0000FF'>Còn: ".$row['soluong']."<br>";
					echo "<font size='3' color='#0000FF'>Số lượng : ";
					echo "<input style='width:50px' value='1' name='so_luong' onKeyPress='if((event.keyCode< 48)|| (event.keyCode > 57)) {event.returnValue =false}'></font>";
					echo "<br>";
					echo "<div style='overflow:hidden;width:5px;height:3px'></div>";
					echo "<input type='hidden' name='id_sp__nnn' value='$row[idsp]'>";
					echo "<input type='hidden' name='them_vao_gio' value='them_vao_gio'>";
					echo "<input type='image' src='image/chung/mua.gif' style='border:0px solid red'>";
					//echo "<input type='image' src='hinhanh/chung/mua.gif' style='border:0px solid red'>";
				echo "</form>";
				//echo "<a href='#'><img src='hinhanh/chung/mua.gif' width='87px' height='27px'/></a>";
			echo "</div>";
		}
	echo "</div>";
    echo "<div id='trang'>";
    for($i=1;$i<=$st;$i++)
    {
        $link="?thamso=tatca&trang=$i";
        echo "<a href='$link'><font size='4px'>";
        echo $i;
        echo "</font></a>";echo"  ";
    }
    echo "</div>";
?>